package com.example.dllo.my36kr.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.model.CollectBean;
import com.example.dllo.my36kr.model.CollectListBean;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by CPC_272 on 16/8/30.
 */
public class CollectAdapter extends BaseAdapter {
    private Context context;

    ArrayList<CollectBean> collectBeen = new ArrayList<>();

    public CollectAdapter(Context context) {
        this.context = context;
    }


    public void setCollectBeen(ArrayList<CollectBean> collectBeen) {
        this.collectBeen = collectBeen;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return collectBeen != null ? collectBeen.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return collectBeen != null ? collectBeen.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_collect, parent, false);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        switch (collectBeen.get(position).getTag()) {
            case "早期项目":
                holder.tv_tag.setTextColor(Color.GREEN);
            case "大公司":
                holder.tv_tag.setTextColor(Color.rgb(85, 164, 255));
                break;
            case "资本":
                holder.tv_tag.setTextColor(Color.BLUE);
                break;
            case "深度":
                holder.tv_tag.setTextColor(Color.RED);
                break;
            case "B轮后":
                holder.tv_tag.setTextColor(Color.rgb(98, 197, 245));
                break;
            case "研究":
                holder.tv_tag.setTextColor(Color.YELLOW);
                break;
        }
        holder.tv_title.setText(collectBeen.get(position).getUseTitle());
        holder.tv_tag.setText(collectBeen.get(position).getTag());
        Picasso.with(context).load(collectBeen.get(position).getUsePic()).resize(70, 70).into(holder.img_news);
        return convertView;
    }

    class MyViewHolder {
        private ImageView img_news;
        private TextView tv_title, tv_tag;

        public MyViewHolder(View view) {
            img_news = (ImageView) view.findViewById(R.id.img_ls_news);
            tv_title = (TextView) view.findViewById(R.id.tv_title_news);
            tv_tag = (TextView) view.findViewById(R.id.tv_tag_news);
        }
    }
}
